/*
 * inotify-sync - a simple file synchronizer and file system watcher
 * Copyright (C) 2010-2011, inotify-sync developers and inotify-sync contributors
 * Copyright (C) 2010-2011, Cohesion Network Security Studio
 *
 * inotify-sync is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * inotify-sync is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with inotify-sync; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/*
 * FILE:		profile_parser.c
 * USAGE:		---
 * DESCRIPTION:		---
 * OPTIONS:		---
 * REQUIREMENTS:	---
 * BUGS:		---
 * NOTES:		---
 * AUTHOR:		LI Yiwei (mail:leeyiw@gmail.com)
 * COMPANY:		---
 * VERSION:		1.0
 * CREATED:		Sat Nov 19 17:09:10 CST 2011
 * REVISION:		---
 */

#include "profile_parser.h"

void
get_profile(const char *profile_path)
{
	FILE *fp = NULL;
	char buf[1000] = {'\0'};
	char *equal = NULL;
	char *end = NULL;

	profile_init();

	if((fp = fopen(profile_path, "r")) == NULL)
	{
		perror(profile_path);
		exit(errno);
	}

	while(NULL != fgets(buf, sizeof(buf), fp))
	{
		if(is_note(buf))
		{
			continue;
		}
		if((equal = strchr(buf, '=')) == NULL
		|| (end = strchr(buf, '\n')) == NULL)
		{
			continue;
		}
		*equal = '\0';
		*end = '\0';
		add_popt(buf, equal + 1);

		memset(buf, '\0', sizeof(buf));
	}
	fclose(fp);
}

int
is_note(char *buf)
{
	if(buf[0] == '#')
	{
		return 1;
	}
	return 0;
}
